package com.tf.integrated.controller;

import com.ccssoft.m8.common.web.BaseController;
import com.tf.integrated.config.Config;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 预警布控-人脸属性接口
 * @author allen
 * @date: 2020年9月14日上午10:56:20
 */
@Api(value = "预警布控-人脸属性接口",description="WarningfaceAttrController")
@RestController
@RequestMapping("/warning/faceAttr")
public class WarningfaceAttrController extends BaseController
{
    @ApiOperation("查询预警布控-人脸属性")
    @GetMapping("/")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String select(@RequestParam Map<String, String> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            String query =  Config.buildMap(data);
            HttpMethod method = HttpMethod.GET;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            logger.error("select on  warning/faceAttr query===" + query);
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/warning/faceAttr/?"+query,method,null,headers);
            logger.error("select on  warning/faceAttr analyseResults===" + analyseResults);
            LogController.add("/warning/faceAttr/",LogController.METHOD_GET,1);
            return analyseResults;
        }
        LogController.add("/warning/faceAttr/",LogController.METHOD_GET,0);
        return "{}";
    }

    @ApiOperation("修改预警布控-人脸属性")
    @PutMapping("/")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String change(@RequestParam Map<String, String> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            String query =  Config.buildMap(data);
            HttpMethod method = HttpMethod.PUT;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/warning/faceAttr/?"+query,method,null,headers);
            logger.error("change on  warning/faceAttr analyseResults===" + analyseResults);
            LogController.add("/warning/faceAttr/",LogController.METHOD_PUT,1);
            return analyseResults;
        }
        LogController.add("/warning/faceAttr/",LogController.METHOD_PUT,0);
        return "{}";
    }

    @ApiOperation("新增预警布控-人脸属性")
    @PostMapping("/")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String update(@RequestParam Map<String, String> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            String query =  Config.buildMap(data);
            HttpMethod method = HttpMethod.POST;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            logger.error("update on  warning/faceAttr query===" + query);
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/warning/faceAttr/?"+query,method,null,headers);
            logger.error("update on  warning/faceAttr analyseResults===" + analyseResults);
            LogController.add("/warning/faceAttr/",LogController.METHOD_POST,1);
            return analyseResults;
        }
        LogController.add("/warning/faceAttr/",LogController.METHOD_POST,0);
        return "{}";
    }

    @ApiOperation("删除预警布控-人脸属性")
    @DeleteMapping("/")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String iddelete(@RequestParam Map<String, String> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            String query =  Config.buildMap(data);
            HttpMethod method = HttpMethod.DELETE;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            logger.error("iddelete on  warning/faceAttr query===" + query);
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/warning/faceAttr/?"+query,method,null,headers);
            logger.error("iddelete on  warning/faceAttr analyseResults===" + analyseResults);
            LogController.add("/warning/faceAttr/",LogController.METHOD_DELETE,1);
            return analyseResults;
        }
        LogController.add("/warning/faceAttr/",LogController.METHOD_DELETE,0);
        return "{}";
    }

    @ApiOperation("查询指定ID预警布控-人脸属性")
    @GetMapping("/byid")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String idselect(@RequestParam Map<String, String> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            String query =  Config.buildMap(data);
            HttpMethod method = HttpMethod.GET;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            logger.error("idselect on  warning/faceAttr query===" + query);
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/warning/faceAttr/?"+query,method,null,headers);
            logger.error("idselect on  warning/faceAttr analyseResults===" + analyseResults);
            LogController.add("/warning/faceAttr/byid",LogController.METHOD_GET,1);
            return analyseResults;
        }
        LogController.add("/warning/faceAttr/byid",LogController.METHOD_GET,0);
        return "{}";
    }
}